﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using TodoList.Converter;
using TodoList.ViewModel;
using TodoList.Common;
using TodoList.Mode;
using TodoList.View;
using FirstFloor.ModernUI.Windows.Controls;

namespace TodoList.Command
{
    class FilterCommand : ICommand
    {
        #region ICommand Members
        TodoBind todoMerge;
        //TodoVM vm;
        public bool CanExecute(object parameter)
        {
            //if (parameter == null) return false;
            //else return true;
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            TodoBind todoMerge = parameter as TodoBind;
            TodoVM vm = todoMerge.TodoViewModel;
            string arg = todoMerge.ObjectType.ToString();  
          
            List<Todo> todoList = Utils.GetTodoList(vm.FileName);
            List<Todo> filtered = null;            
            filtered = todoList.Where(to => to.State.Equals(arg)).ToList<Todo>();
            vm.TodoList = filtered;           
        }
        #endregion
    }
}
